package com.cscec.omega.config;

import com.cscec.omega.dao.ApiDao;
import com.cscec.omega.entity.APIEntity;
import com.cscec.omega.utils.SchemaUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 初始化服务
 * guava
 */
@Component
public class InitService implements CommandLineRunner {

    @Autowired
    private ApiDao apiDao;

    @Override
    public void run(String... args) throws Exception {
        initSchema();
    }

    /**
     * 初始化schemaJSON
     */
    private void initSchema(){
        List<APIEntity> list = apiDao.findAllByStatus(1);//再用的接口
        String key;
        for (APIEntity api: list) {
            key = api.getUrl()+"/"+api.getFunctionName();
            SchemaUtil.addSchema(key, api.getSchema());
        }
    }
}
